package cn.tanghom.app.oa.service.impl;

import io.netty.util.internal.StringUtil;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;


import cn.tanghom.app.oa.model.Talent;
import cn.tanghom.app.oa.service.ResumeService;
import cn.tanghom.app.system.aop.ConfigApplication;

public class ResumeServiceWarper implements ResumeService {
	

	static Map<String, ResumeService>  sourceMap = null;
	
	
	private ResumeService getResumeService(String source) {
		// TODO Auto-generated method stub
		if(sourceMap==null){			
			sourceMap = ConfigApplication.getBeansOfType(ResumeService.class);			
		}
		if(source ==null || source.isEmpty()){
			source = "resumeService";
			ResumeService resumeService = sourceMap.get(source);		
			return resumeService;
		}
		String[] sourcePair = StringUtil.split(source,':');
		ResumeService resumeService = sourceMap.get(sourcePair[0]);		
		return resumeService;
	}
	
	/**
	 * 如果简历的id不是long类型，则 source的格式为：sourceName:sourceKey
	 */
	@Override
	public Talent getResume(String source, Long id) {		
		ResumeService resumeService = getResumeService(source);
		Talent resume = resumeService.getResume(source, id);
		return resume;
	}

	@Override
	public boolean updateResume(String source, Talent a) {
		ResumeService resumeService = getResumeService(source);
		boolean rc = resumeService.updateResume(source, a);
		return rc;		
	}

	@Override
	public List<Talent> findResume(String source, Map<String, String> query) {
		ResumeService resumeService = getResumeService(source);
		return resumeService.findResume(source,query);
	}

}
